<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'sheBeiMingCheng', validatorRules.sheBeiMingCheng]" placeholder="请输入设备名称"></a-input>
        </a-form-item>
        <a-form-item label="设备类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['sheBeiLeiBie', validatorRules.sheBeiLeiBie]" :trigger-change="true" dictCode="gkak_sblb" placeholder="请选择设备类别"/>
        </a-form-item>
        <a-form-item label="设备序列号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'sheBeiXuLieHao', validatorRules.sheBeiXuLieHao]" placeholder="请输入设备序列号"></a-input>
        </a-form-item>
        <a-form-item label="设备参数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'sheBeiCanShu', validatorRules.sheBeiCanShu]" placeholder="请输入设备参数"></a-input>
        </a-form-item>
        <a-form-item label="设备属性" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'sheBeiShuXing', validatorRules.sheBeiShuXing]" placeholder="请输入设备属性"></a-input>
        </a-form-item>
        <a-form-item label="发放状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['faFangZhuangTai', validatorRules.faFangZhuangTai]" :trigger-change="true" dictCode="gkak_ffzt" placeholder="请选择发放状态"/>
        </a-form-item>
        <a-form-item label="归档人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'guiDangRen', validatorRules.guiDangRen]" placeholder="请输入归档人"></a-input>
        </a-form-item>
        <a-form-item label="归档时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择归档时间" v-decorator="[ 'guiDangShiJian', validatorRules.guiDangShiJian]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="厂家信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'changJiaXinXi', validatorRules.changJiaXinXi]" placeholder="请输入厂家信息"></a-input>
        </a-form-item>
        <a-form-item label="备注信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'beiZhuXinXi', validatorRules.beiZhuXinXi]" placeholder="请输入备注信息"></a-input>
        </a-form-item>
        <a-form-item label="机构类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['jiGouType', validatorRules.jiGouType]" :trigger-change="true" dictCode="gkak_sbjglx" placeholder="请选择机构类型"/>
        </a-form-item>
        <a-form-item label="所属机构" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-depart v-decorator="['jiGouId', validatorRules.jiGouId]" :trigger-change="true"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "GkakSbSheBeiXinXiModal",
    components: { 
      JDate,
      JSelectDepart,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          sheBeiMingCheng: {rules: [
            {required: true, message: '请输入设备名称!'},
          ]},
          sheBeiLeiBie: {rules: [
            {required: true, message: '请输入设备类别!'},
          ]},
          sheBeiXuLieHao: {rules: [
            {required: true, message: '请输入设备序列号!'},
          ]},
          sheBeiCanShu: {rules: [
          ]},
          sheBeiShuXing: {rules: [
          ]},
          faFangZhuangTai: {rules: [
            {required: true, message: '请输入发放状态!'},
          ]},
          guiDangRen: {rules: [
          ]},
          guiDangShiJian: {rules: [
          ]},
          changJiaXinXi: {rules: [
          ]},
          beiZhuXinXi: {rules: [
          ]},
          jiGouType: {rules: [
          ]},
          jiGouId: {rules: [
          ]},
        },
        url: {
          add: "/gkakSbSheBeiXinXi/add",
          edit: "/gkakSbSheBeiXinXi/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'sheBeiMingCheng','sheBeiLeiBie','sheBeiXuLieHao','sheBeiCanShu','sheBeiShuXing','faFangZhuangTai','guiDangRen','guiDangShiJian','changJiaXinXi','beiZhuXinXi','jiGouType','jiGouId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'sheBeiMingCheng','sheBeiLeiBie','sheBeiXuLieHao','sheBeiCanShu','sheBeiShuXing','faFangZhuangTai','guiDangRen','guiDangShiJian','changJiaXinXi','beiZhuXinXi','jiGouType','jiGouId'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>